﻿using deviceManage.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace deviceManage.Service
{
    /// <summary>
    /// 文档管理服务类
    /// </summary>
    public class DocumentService
    {
        private readonly DeviceCtx _context;
        public DocumentService(DeviceCtx _context)
        {
            this._context = _context;
        }

        
        /// <summary>
        /// 获取文档类型列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<DocumentType> GetDocumentTypeList(string type)
        {
            IQueryable<DocumentType> q = _context.DocumentType.Where(p => p.Deleted == 0);
            if (!string.IsNullOrWhiteSpace(type))
            {
                q = q.Where(p => p.Name == type);
            }

            return q.OrderBy(p=>p.SortOrder).ToList();
        }
        /// <summary>
        /// 获取文档类型列表
        /// </summary>
        /// <returns></returns>
        public List<DocumentType> GetDocumentTypeList()
        {
            return this.GetDocumentTypeList(null);
        }


        public Document GetById(string id)
        {
            return _context.Document.Single(p => p.Id == id);
        }
    }
}
